package com.efast.dmom.mes.controller;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @author lyx
 * @date 2020/01/08
 */
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.bean.WorkingCalendar;
import com.efast.dmom.mes.service.WorkingCalendarService;

@Controller
@RequestMapping("/workingCalendar")
public class WorkingCalendarController {

	@Autowired
	private WorkingCalendarService workingCalendarService;

	/**
	 * 批量新增日历
	 * 
	 * @param workingCalendar
	 * @return
	 */
	@RequestMapping("/insertWorkingCalendar")
	public @ResponseBody ResultBean insertWorkingCalendar(@RequestBody WorkingCalendar workingCalendar) {
		ResultBean result = workingCalendarService.insertWorkingCalendar(workingCalendar);
		return result;
	}

	/**
	 * 更新方法
	 * 
	 * @param workingCalendar
	 * @return
	 */
	@RequestMapping("/updateWorkingCalendar")
	public @ResponseBody ResultBean updateWorkingCalendar(@RequestBody WorkingCalendar workingCalendar) {
		ResultBean result = workingCalendarService.updateWorkingCalendar(workingCalendar);
		return result;
	}

	/**
	 * 查询某一时间段的日历信息
	 * 
	 * @param workingCalendar
	 * @return
	 */
	@RequestMapping("/getworkCanlendarByMonth")
	public @ResponseBody ResultBean getworkCanlendarByMonth(@RequestBody WorkingCalendar workingCalendar) {
		ResultBean result = workingCalendarService.getworkCanlendarByMonth(workingCalendar);
		return result;

	}
	/**
	 * 删除班次
	 * @param shiftId
	 * @return
	 */
	@RequestMapping("/deleteShift")
	public@ResponseBody ResultBean deleteShift(@RequestBody WorkingCalendar workingCalendar) {
//		workingCalendar.setCurrentDate(LocalDate.of(2020, 1, 17));
		ResultBean result=workingCalendarService.deleteShift(workingCalendar);
		return result;
		
	}
	
	/**
	 * 根据日期查询班次
	 * @param WorkingCalendar
	 * @return
	 */
	@RequestMapping("/selectShift")
	public@ResponseBody ResultBean selectShift(@RequestBody WorkingCalendar workingCalendar) {
	   
	// dateTimeStr = "2020-01-17";
	//	DateTimeFormatter df1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
		
//		LocalDateTime dateTime = LocalDateTime.parse(dateTimeStr, df1);
//		workingCalendar.setCurrentDate(LocalDate.of(2020, 1, 17));
		ResultBean result=workingCalendarService.selectShift(workingCalendar);	
		return result;
	}
	
	@RequestMapping(value = "/test001")
	public @ResponseBody ResultBean getWorkingHoursPerDay () {
		long workshopId = 3;
		long plantId = 1;
		long lineId = 5;
		LocalDate startTime = LocalDate.now();
		LocalDate endTime = LocalDate.now();
		Map<LocalDate, WorkingCalendar> workingHoursPerDay = workingCalendarService.getWorkingHoursPerDay(plantId ,workshopId, lineId, startTime, endTime);
		ResultBean resultBean = new ResultBean(true);
		resultBean.setObject(workingHoursPerDay);
		return resultBean;
	}
	
/**
 * 查询指定时间段内工作日历的状态（工作，休息）和每天的排产总量和已排产量
 * **/
	@RequestMapping(value = "/selectcalendarsAndSchedulingCount")
	
	public @ResponseBody ResultBean selectcalendarsAndSchedulingCount (@RequestBody WorkingCalendar workingCalendar) {
		ResultBean resultBean = new ResultBean(true);
		workingCalendarService.selectcalendarsAndSchedulingCount(workingCalendar);
		return resultBean;
	}
	
	/**
	 * 通过指定的日历时间查询当前日期下的班次信息
	 * **/
	@RequestMapping(value = "/queryShiftInfoByCalendar")
	public @ResponseBody ResultBean queryShiftInfoByCalendar(@RequestBody WorkingCalendar workingCalendar) {
		ResultBean resultBean = new ResultBean(true);
		List<Map<String, Object>> queryShiftInfoByCalendar = workingCalendarService.queryShiftInfoByCalendar(workingCalendar);
		resultBean.setObject(queryShiftInfoByCalendar);
		return resultBean;
	}
	
	/**
	 * 通过产线和指定的时间段查询其下所有的时间数据
	 * **/
	@RequestMapping(value = "/queryCalendarByStartDataEndData")
	public @ResponseBody ResultBean querycalendarBystartDataEndData(@RequestBody Map<String,Object> map) {
		ResultBean resultBean = new ResultBean(true);
		List<Map<String, Object>> querycalendarBystartDataEndData = workingCalendarService.querycalendarBystartDataEndData(map);
		resultBean.setObject(querycalendarBystartDataEndData);
		return resultBean;
	}
	/**
	 * 通过产线更新日历状态
	 * **/
	@RequestMapping(value = "/updateCalendarStatus")
	public @ResponseBody ResultBean updateCalendarStatus(@RequestBody Map<String,Object> map) {
		return workingCalendarService.updateCalendarStatus(map);
	} 
	
	/**
	 * // 新增工作日历和班次关系
	 * **/
	@RequestMapping(value = "/addCalendarShiftRel")
	public @ResponseBody ResultBean addCalendarShiftRel(@RequestBody Map<String,Object> map) {

		ResultBean addCalendarShiftRel = workingCalendarService.addCalendarShiftRel(map);
		
		return addCalendarShiftRel;
	}
	
	/**
	 * // 删除工作日历和班次关系
	 * **/
	@RequestMapping(value = "/deleteCalendarShiftRel")
	public @ResponseBody ResultBean deleteCalendarShiftRel(@RequestBody Map<String,Object> map) {
		ResultBean resultBean = new ResultBean(true);
		workingCalendarService.deleteCalendarShiftRel(map);
		return resultBean;
	}
	
}
